export default {
    namespaced:true,
    state:{
        address:uni.getStorageSync('address'),
        userInfo:uni.getStorageSync('userInfo'),
        token:uni.getStorageSync('token'),
        redirectInfo:null
    },

    getters:{
        getAddress(state){
            return state.address
        },
        addstr(state){
            if (!state.address || !state.address.provinceName) {return ''}
            //将数据拼接，成字符串返回
            return(
                state.address.provinceName +
                state.address.cityName +
                state.address.countyName +
                state.address.detailInfo
            )
        },
        getUserInfo(state){
            return state.userInfo
        },
        getToken(state){
            return state.token
        },
        getRedirectInfo(state){
            return state.redirectInfo
        }
    },

    mutations:{
        updateAddress(state,address){
            state.address = address
            this.commit('m_user/saveAddressToStorage')
        },

        saveAddressToStorage(state){
            uni.setStorageSync('address',state.address)
        },

        updateUserInfo(state,userInfo){
            state.userInfo = userInfo
            this.commit('m_user/saveUserInfoToStorage')
        },
        
        saveUserInfoToStorage(state){
            uni.setStorageSync('userInfo',state.userInfo)
        },

        updateToken(state,token){
            state.token = token
            this.commit('m_user/saveTokenToStorage')
        },

        saveTokenToStorage(state){
            uni.setStorageSync('token',state.token)
        },

        updateRedirectInfo(state,info){
            state.redirectInfo = info
        }
    }
}